const path = require("path");
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const {CheckerPlugin} = require("awesome-typescript-loader");

module.exports = {
    entry: {
        main: path.resolve(__dirname, "../src/main.tsx")
    },
    output: {
        filename: "[name].[hash].js",
        path: path.resolve(__dirname, "../dist"),
        publicPath: "/"
    },
    resolve: {
        extensions: [".js",".css",".scss",".ts",".tsx"],
        alias:{
            "@": path.resolve(__dirname, "../src"),
            "@@": path.resolve(__dirname, "../static"),
        }

    },

    module: {
        rules: [
            {
                test: /\.js$/,
                loader: "babel-loader?cacheDirectory=true",
                exclude: /node_modules/
            },
            {
                test: /\.tsx?$/,
                loader: "awesome-typescript-loader",
                exclude: /node_modules/
            },
            {
                test: /\.(png|jpe?g|gif|svg|ico)(\?.*)?$/,
                loader: "file-loader?name=static/img/[name].[hash:7].[ext]",
            },
            {
                test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
                loader: 'file-loader',
                options: {
                    limit: 10000,
                    name: path.join("static/", "img/[name].[hash:7].[ext]")
                }
            },
            {
                test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
                loader: 'file-loader',
                options: {
                    limit: 10000,
                    name: path.join("static/", "font/[name].[hash:7].[ext]")
                }
            },
        ]
    },
    target: "electron-renderer",
    plugins: [
        // 代码分割
        new CheckerPlugin(),
        new webpack.optimize.CommonsChunkPlugin({
            name:"commons",
            filename:"commons.js"
        }),
        new HtmlWebpackPlugin({
            title: "XunMang",
            filename: "index.html",
            template:  path.resolve(__dirname, "../index.html"),
            hash: true,
            minify: true,
            cache: true,
        })
    ]
};
